package com.snake.springboot.authority.web.controller;

import com.snake.springboot.authority.api.model.AuthStrategyModel;
import com.snake.springboot.authority.api.request.AuthStrategyQuery;
import com.snake.springboot.authority.api.service.AuthStrategyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.snake.common.result.ReturnList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类 {@code AuthStrategyController}  <br> .
 * <p>权限策略控制器
 * <p>创建时间：2025/02/08
 *
 * @author Huang.yj
 */
@Api(tags = "权限管理-权限策略")
@RestController
@RequestMapping("/auth/strategy")
public class AuthStrategyController {

    private AuthStrategyService authStrategyService;

    @Autowired
    public AuthStrategyController(AuthStrategyService authStrategyService){
        this.authStrategyService = authStrategyService;
    }

    @ApiOperation("添加权限策略")
    @PostMapping("/add")
    public ResponseResult<AuthStrategyModel> addAuthStrategy(
            @ApiParam(name = "权限策略入参", value = "传入json格式", required = true)
            @RequestBody AuthStrategyModel model) throws Exception{
        AuthStrategyModel result = authStrategyService.addAuthStrategy(model);
        return ResponseResultFactory.ucc("添加成功",result);
    }

    @ApiOperation("修改权限策略")
    @PostMapping("/modify")
    public ResponseResult<AuthStrategyModel> modifyAuthStrategy(
            @ApiParam(name = "权限策略入参", value = "传入json格式", required = true)
            @RequestBody AuthStrategyModel model) throws Exception{
        AuthStrategyModel result = authStrategyService.modifyAuthStrategy(model);
        return ResponseResultFactory.ucc("修改成功",result);
    }

    @ApiOperation("删除权限策略")
    @GetMapping("/remove/{strategyid}")
    public ResponseResult<Object> removeAuthStrategy(
            @ApiParam(name = "权限策略入参", value = "传入string格式", required = true)
            @PathVariable("strategyid") String strategyId){
        authStrategyService.removeAuthStrategy(strategyId);
        return ResponseResultFactory.ucc("移除成功");
    }

    @ApiOperation("查询权限策略")
    @GetMapping("/detail/{strategyid}")
    public ResponseResult<AuthStrategyModel> queryAuthStrategy(
            @ApiParam(name = "权限策略入参", value = "传入string格式", required = true)
            @PathVariable("strategyid") String strategyId){
        AuthStrategyModel result = authStrategyService.queryAuthStrategy(strategyId);
        return ResponseResultFactory.ucc("查询成功",result);
    }

    @ApiOperation("查询权限策略")
    @PostMapping("/list")
    public ResponseResult<List<AuthStrategyModel>> queryAuthStrategyList(
            @ApiParam(name = "权限策略入参", value = "传入json格式", required = true)
            @RequestBody AuthStrategyModel model) throws Exception{
        List<AuthStrategyModel> result = authStrategyService.queryAuthStrategyList(model);
        return ResponseResultFactory.ucc("查询成功",result);
    }

    @ApiOperation("分页查询权限策略")
    @PostMapping("/page_list")
    public ResponseResult<ReturnList<AuthStrategyModel>> queryAuthStrategyList(
            @ApiParam(name = "权限策略入参", value = "传入json格式", required = true)
            @RequestBody AuthStrategyQuery query) throws Exception{
        ReturnList<AuthStrategyModel> result = authStrategyService.queryAuthStrategyList(query);
        return ResponseResultFactory.ucc("查询成功",result);
    }

}
